function websocket(url){
	var websocket = new WebSocket(url);
	return {
		open:function(func){
			websocket.onopen = func != undefined ? func : function(evt){
				console.log(evt);
			};
		},
		close:function(func){
			websocket.onclose = func != undefined ? func : function(evt){
				console.log(evt);
			};
		},
		message:function(func){
			websocket.onmessage = func != undefined ? func : function(evt){
				console.log(evt.data);
			};
		},
		error:function(func){
			websocket.onerror = func != undefined ? func : function(evt){
				console.log(evt.data);
			};
		},
		send:function(type,content){
			websocket.send(JSON.stringify({"type":type,"data":content}));
		}
	}
}